/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.swta;

import java.util.Iterator;
import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
import org.apache.wicket.model.IModel;

/**
 *
 * @author JKorreck
 */
public class SortableItemsProvider extends SortableDataProvider {

    public SortableItemsProvider() {
        setSort("id", true);
    }



    public Iterator iterator(int first, int count) {
        SortParam sp = getSort();
        String property = sp.getProperty();
        boolean isAsc = sp.isAscending();
        
        return MyItemManager.getInstance().find(first, count, property, isAsc).iterator();
    }

    public int size() {
        return MyItemManager.getInstance().getSize();
    }

    public IModel model(Object item) {
        return new DetacheableItemsModel((MyItem) item);
    }

}
